﻿using System;
using System.Data.Common;
using System.Data.SqlClient;
using CSW.Framework.Linq.SchemaModel;

namespace CSW.Framework.Linq
{
    /// <summary>
    /// IDatabase interface.
    /// </summary>
    public interface IDatabase
    {
        /// <summary>
        /// Gets the connection string.
        /// </summary>
        /// <value>The connection string.</value>
        string ConnectionString { get; }

        /// <summary>
        /// Gets the database schema model.
        /// </summary>
        /// <value>The database schema model.</value>
        Database Schema { get; }

        /// <summary>
        /// Gets the <see cref="Type"/> of a <see cref="Table"/>.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <returns>The <see cref="Type"/> of the specified <see cref="Table"/>.</returns>
        Type GetTableType(Table table);

        /*/// <summary>
        /// Gets a table object implementing IOrderedQueryable&lt;T&gt; and IQueryProvider.
        /// </summary>
        /// <typeparam name="T">The table object type.</typeparam>
        /// <returns>The table object implementing IOrderedQueryable&lt;T&gt; and IQueryProvider.</returns>
        ITableQueryProvider<T> GetTable<T>();*/

        /// <summary>
        /// Executes the SQL statement.
        /// </summary>
        /// <param name="sql">The SQL statement.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>The affected row count.</returns>
        int ExecuteSql(string sql, DbParameter[] parameters);

        /// <summary>
        /// Executes the SQL statement.
        /// </summary>
        /// <param name="sql">The SQL statement.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>The inserted record's identity value.</returns>
        int ExecuteIdentityInsert(string sql, DbParameter[] parameters);

        /// <summary>
        /// Gets the SQL connection for the current thread.
        /// </summary>
        /// <returns>The SQL connection for the current thread.</returns>
        DbConnection GetThreadConnection();
    }
}
